package com.wxzl.community.common.http;

import android.util.Log;

import java.lang.reflect.Field;

import rxhttp.wrapper.annotation.Param;
import rxhttp.wrapper.param.FormParam;
import rxhttp.wrapper.param.Method;

/**
 * 提交一个简单java对像。转换成url
 */
@Param(methodName = "putJavaBean")
public class PutJavaBeanFormParam extends FormParam {

    public PutJavaBeanFormParam(String url) {
        super(url, Method.PUT);
    }
    /**
     * 简单java对像
     */
    public PutJavaBeanFormParam add(Object clazz) {
        //这里的业务逻辑自行实现
        Field[] fields = clazz.getClass().getDeclaredFields();
        try {

            for (int i = 0; i < fields.length; i++) {
                Field field = fields[i];
                // 允许访问私有变量
                field.setAccessible(true);

                // 属性名
                String property = field.getName();
                // 属性值
                Object  value = field.get(clazz);
                if (value != null){
                    this.add(property,value);
                }




            }
        } catch (Exception e) {
             Log.e("PostJavaBeanFormParam","URL参数为：" + clazz.toString());
        }


        return this;
    }

}